<template>
  <div class="">

    <el-table border v-loading="loading" :data="dataList"  ref="table"  :max-height="tableMaxHeight">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column sortable label="生产单号" align="center" prop="produceNo" show-overflow-tooltip />
      <el-table-column sortable label="项目编号" align="center" prop="projectCode" show-overflow-tooltip />
      <el-table-column sortable label="产品编号" align="center" prop="goodsCode" />
      <el-table-column sortable label="产品名称" align="center" prop="goodsName" show-overflow-tooltip />
      <el-table-column sortable label="产品型号" align="center" prop="goodsModel" />
      <el-table-column sortable label="工序名称" align="center" prop="name" />
      <el-table-column sortable label="图纸号" align="center" prop="shuoming" />
      <el-table-column sortable label="生产产品名称" align="center" prop="gongxuName" />
      <el-table-column sortable label="生产产品型号" align="center" prop="gongxuModel" />
      <el-table-column sortable label="车间" align="center" prop="deptName" />
      <el-table-column sortable label="姓名" align="center" prop="userName" />
      <el-table-column sortable label="报工时间" align="center" prop="doTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.doTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column sortable label="报工数量" align="center" prop="count" />
      <el-table-column sortable label="单价" align="center" prop="money" />
      <el-table-column sortable label="合格数量" align="center" prop="successCount" />
      <el-table-column sortable label="不合格数量" align="center" prop="errorCount" />
      <el-table-column sortable label="合格总价" align="center" prop="allMoney" />
      <el-table-column sortable label="合格率(%)" align="center" prop="successLv" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="180">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-set-up"
                     @click="qualityTestingProcess(scope.row)">生产工序质检
          </el-button>
        </template>
      </el-table-column>

    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"/>
    <factory-test-quality-process ref="qualityTestingProcess" @ok="getList"> </factory-test-quality-process>
  </div>
</template>

<script>
  import {deleteAction, getAction} from '@/api/manage'
  import FactoryTestQualityGoods from "@/views/develop/factory/factoryTestQuality/FactoryTestQualityGoods.vue";
  import FactoryTestQualityProcess from "@/views/develop/factory/factoryTestQuality/FactoryTestQualityProcess.vue";

  export default {
    name: "FactoryProductProcessList",
    components: {
      FactoryTestQualityProcess,
      FactoryTestQualityGoods
    },
    props: {
      rukuId: {
        type: String,
        default: null
      },
      goodsId: {
        type: String,
        default: null
      },
      factoryGoodssaleId: {
        type: String,
        default: null
      },
    },
    watch: {

      factoryGoodssaleId: {
        handler(newVal, oldVal) {
          this.queryParams.saleId = newVal;
          if(newVal){
            this.getList();
          }else{
            this.dataList = [];
            this.loading = false;
          }
        },
        immediate: true
      },

    },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 生产过程数据表格数据
        dataList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          projectId: null,
          orderId: null,
          goodsId: null,
          goodsName: null,
          goodsModel: null,
          batchNumber: null,
          processMethod: null,
          processCount: null,
          finishTime: null,
          saleId: null,
        },
        url: {
          list: '/goodsSaledoGongxuUserMoney/goodsSaledoGongxuUserMoney/listAndParent',
        },
        tableMaxHeight: window.innerHeight - 320,
      };
    },
    created() {
      window.addEventListener('resize', this.getTableHeight);
    },
    destroyed() {
      window.removeEventListener('resize', this.getTableHeight)
    },
    methods: {
      /** 查询生产过程数据列表 */
      getList() {
        this.loading = false;
        getAction(this.url.list, this.queryParams).then(response => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },

      getTableHeight() {
        this.tableHeight = window.innerHeight - 320
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },

      qualityTestingProcess(row){
        if(row.status==='0'){
          this.$refs.qualityTestingProcess.showByProcess(row,true);
        }else{
          this.$refs.qualityTestingProcess.showByProcess(row,false);
        }
      }

    }
  };
</script>
